package com.doubao.doubao.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.doubao.doubao.common.api.ApiResult;
import com.doubao.doubao.mapper.BmsAffairrsMapper;
import com.doubao.doubao.model.entity.BmsAffairs;
import com.doubao.doubao.model.entity.BmsReFiles;
import com.doubao.doubao.service.IBmsAffairservice;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/Affairs")
public class BmsAffairsController extends BaseController {

    @Resource
    private IBmsAffairservice iBmsAffairservice;
    @Resource
    BmsAffairrsMapper bmsAffairrsMapper;



    @RequestMapping(value = "/getAffairsList", method = RequestMethod.GET)
    public ApiResult<?> findPage(@RequestParam(value = "groupid", defaultValue = "1")String groupid){
        List<Map<String, Object>> BookPage =  bmsAffairrsMapper.selectMaps(new LambdaQueryWrapper<BmsAffairs>().eq(BmsAffairs::getGroupId, groupid));
        return ApiResult.success(BookPage);
    }



    @PostMapping("/addAffairs")
    public ApiResult<BmsAffairs> addAffairs(@RequestBody BmsAffairs bmsAffairs) {
        BmsAffairs res =  bmsAffairrsMapper.selectOne(Wrappers.<BmsAffairs>lambdaQuery()
                .eq(BmsAffairs::getAffairsName,bmsAffairs.getAffairsName()));
        if(res!=null){
            return ApiResult.failed("当前事务已存在，请不要重复添加");
        }
        iBmsAffairservice.save(bmsAffairs);
        return ApiResult.success(bmsAffairs);
    }

}
